package it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.filter;

import javax.servlet.jsp.JspException;

import it.blueocean.acanto.taglibrary.jsp.taglib.tags.AbstractComponentStateBean;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.AbstractUIComponentTag;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.DataSet;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.DataSetTag;
import it.blueocean.acanto.taglibrary.jsp.taglib.tags.exceptions.ComponentStateBeanNotFoundException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DatasetFilterTag extends AbstractUIComponentTag
{
	private static final long serialVersionUID = 840156000L;

	private final static Logger logger_ = LoggerFactory.getLogger(DatasetFilterTag.class);

	private boolean orMode;

	private boolean notMode;

	public AbstractComponentStateBean initializeState() throws JspException
	{
		return new DatasetFilterStateBean();
	}

	public int doStartTag(AbstractComponentStateBean paramAbstractComponentStateBean) throws JspException
	{
		DatasetFilterStateBean localDatasetFilterStateBean = (DatasetFilterStateBean) paramAbstractComponentStateBean;
		
		localDatasetFilterStateBean.setOrModeOn(this.orMode);
		localDatasetFilterStateBean.setOrModeOn(this.orMode);
		localDatasetFilterStateBean.setNotModeOn(this.notMode);
		
		return 2;
	}

	public int doEndTag(AbstractComponentStateBean paramAbstractComponentStateBean) throws JspException
	{
		DatasetFilterTag localDatasetFilterTag = (DatasetFilterTag) findAncestorWithClass(this, DatasetFilterTag.class);
		
		if(localDatasetFilterTag != null)
		{
			try
			{
				localDatasetFilterTag.addFilterCondition((DatasetFilterStateBean) paramAbstractComponentStateBean);
			}
			catch (ComponentStateBeanNotFoundException localComponentStateBeanNotFoundException1)
			{
				logger_.error(localComponentStateBeanNotFoundException1.getMessage());
			}
		}
		else
		{
			DataSetTag localDataSetTag = (DataSetTag) findAncestorWithClass(this, DataSetTag.class);
			
			if(localDataSetTag != null)
			{
				
				try
				{
					DataSet localDataSet = (DataSet) localDataSetTag.getStateBean();
					localDataSet.setFilter((DatasetFilterStateBean) paramAbstractComponentStateBean);
				}
				catch (ComponentStateBeanNotFoundException localComponentStateBeanNotFoundException2)
				{
					logger_.error(localComponentStateBeanNotFoundException2.getMessage());
				}
			}
		}
		
		return 6;
	}

	public void addFilterCondition(DatasetFilter paramDatasetFilter) throws ComponentStateBeanNotFoundException
	{
		DatasetFilterStateBean localDatasetFilterStateBean = (DatasetFilterStateBean) getStateBean();
		localDatasetFilterStateBean.addCondition(paramDatasetFilter);
	}

	public boolean isNotMode()
	{
		return this.notMode;
	}

	public void setNotMode(boolean paramBoolean)
	{
		this.notMode = paramBoolean;
	}

	public boolean isOrMode()
	{
		return this.orMode;
	}

	public void setOrMode(boolean paramBoolean)
	{
		this.orMode = paramBoolean;
	}
}
